<template>
	<view class="container bar">
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{data.title}}</block>
		</cu-custom>
		<view class="head bg-white">
			<view class="bg-red light flex justify-between padding-sm" v-if="data.log.id>0 && showlog">
				<view class="text-lg"><text>上次学习到：{{data.log.datetime}}秒</text></view>
				<view>
					<button class="cu-btn bg-red round sm margin-right" @click="viewSection(data.log.sid)">继续学习</button>
					<text class="text-xl" @click="showlog=false">
						<text class="cuIcon-close"></text>
					</text>
				</view>
			</view>
			<view class="cover">
				<image :src="data.lesson.imgurl" mode="widthFix"></image>
			</view>
			<view class="detail padding-sm margin-top-xs">
				<view class="title">
					<text class="text-xxl text-bold">{{data.lesson.coursebrief}}</text>
				</view>
				<view class="sub-title padding-top-sm padding-bottom-xs">
					<text>{{data.lesson.courseSubhead}}</text>
				</view>
				<view class="flex">
					<view class="flex-sub text-red">
						<text class="text-xxl" v-if="data.lesson.courseprice<=0">{{device=='ios'&&!data.iospay?'':'免费'}}</text>
						<view v-else>
							<text class="text-xxl">{{data.lesson.courseprice}}</text>
							<text>￥</text>
							
						</view>
					</view>
					<view class="flex-sub text-right padding-top-sm">
						<text class="text-black padding-left-sm">{{data.lesson.score==0?'暂无评':data.lesson.score}}分</text>
						<text class="text-gray margin-left-sm">{{data.lesson.studynumber}}人已学</text>
					</view>
				</view>
			</view>
		</view>
		<view class="margin-top-sm bg-white">
			<view class="content-nav nav">
				<view class="cu-item" :class="currentshow=='main'?'cur':''" @click="currentshow='main'">{{data.lesson.multiple==0?'学习':'目录'}}</view>
				<view class="cu-item" :class="currentshow=='content'?'cur':''" @click="currentshow='content'">详情</view>
				<view class="cu-item" :class="currentshow=='comment'?'cur':''" @click="currentshow='comment'">评价({{data.comments.length}})</view>
			</view>
			<view class="content-tab">
				<view class="tab-item padding" :class="currentshow=='main'?'active':''">
					<view>
						<text class="text-grey">共{{data.sections.length}}节课时</text>
					</view>
					<view class="cu-list menu sections">
						<view class="cu-item arrow" @click="viewSection(item.number)" v-for="(item, index) in data.sections" :key="index">
							<view class="content padding-tb-sm">
								<view class="title">
									<image src="@/static/images/img_lesson_play.png" class="png" mode="aspectFit"></image> {{item.title}}
								</view>
								<view class="text-sub padding-left-xxl">
									时长：{{item.duration==''?'未知':item.duration}} <text class="text-gray text-sm margin-left-sm margin-right-sm">|</text> {{item.playnumber}}次{{item.type==2?'学习':'播放'}}
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="tab-item" :class="currentshow=='content'?'active':''">
					<view class="lector padding-sm" v-if="data.lector.uid>0">
						<view class="cu-list menu-avatar" v-if="data.lector.uid>0">
							<view class="cu-item noaf">
								<view class="cu-avatar round lg" :style="'background-image:url('+data.lector.background_Img+');'"></view>
								<view class="content">
									<view class="text-bold">{{data.lector.name}}</view>
									<view class="text-gray text-sm flex">
										<view class="text-cut">
											<div v-if="data.lector.excellent==1">
												金牌讲师(已认证)
											</div>
											<div v-else>
												普通讲师(已认证)
											</div>
										</view>
									</view>
								</view>
								<view class="action" @click="doFavor('lector', data.lector.id)" style="width: 160upx;">
									<button class="cu-btn round" :class="data.lector.hasfavor?'':'bg-gradual-yellow'">{{data.lector.hasfavor?'已订阅':'订阅TA'}}</button>
								</view>
							</view>
						</view>
						<view class="lector-summary padding-sm">
							<text style="font-size: 0.75rem;">{{data.lector.intro}}</text>
						</view>
						<view class="border-bottom text-center padding-bottom" @click="naviTo('lector/detail',{id:data.lector.id})">
							<view class="text-gray">讲师详情<text class="cuIcon-right"></text></view>
						</view>
					</view>
					<view class="padding-sm">
						<view class="flex bg-gray radius text-center padding light">
							<view class="flex-sub">
								<view class="title">课程分类</view>
								<text>{{data.lesson.cname}}</text>
							</view>
							<view class="flex-sub">
								<view class="title">课程章节</view>
								<text>共{{data.sections.length}}节</text>
							</view>
							<view class="flex-sub">
								<view class="title">课程难度</view>
								<text>{{data.lesson.gradedifficulty}}</text>
							</view>
						</view>
						<view class="goods" v-if="data.lesson.goods.switch>0">
							<view class="cu-bar">
								<view class="action title-style-3 margin-0">
									<text class="text-lg text-bold text-black">课程相关商品</text>
								</view>
							</view>
							<view class="cu-list menu-avatar">
								<view class="cu-item" @click="naviTo(data.lesson.goods.url)">
									<view class="cu-avatar lg" :style="'background-image:url('+data.lesson.goods.cover+');'"></view>
									<view class="content">
										<view class="text-black text-cut">{{data.lesson.goods.title}}</view>
										<view class="text-gray text-sm flex">
											<view class="text-cut">
												{{data.lesson.goods.summary}}
											</view>
										</view>
									</view>
									<view class="action">
										<button class="cu-btn bg-gradual-yellow sm round">购买</button>
									</view>
								</view>
							</view>
						</view>
						<view class="margin-top-sm text-lg text-boldm" v-if="data.lesson.courseprice>0 && !data.hasbought">
							<view class="border-bottom padding-top padding-bottom" v-if="data.lesson.discount==1">
								<text class="text-bold text-black">专属折扣：</text>
								<text v-if="data.discounttext==''" :class="data.vipstate==1?'text-novip':''" @click="naviTo('member/vip')">当前会员等级暂无折扣</text>
								<text class="text-orange" v-else>{{data.discounttext}}</text>
							</view>
							<view class="border-bottom padding-top padding-bottom" v-if="data.lesson.deduct==1">
								<text class="text-bold text-black">积分抵扣：</text>
								<text class="text-orange">该课程支持积分抵扣</text>
							</view>
							<view class="border-bottom padding-top padding-bottom" v-if="data.lesson.coupon==1">
								<text class="text-bold text-black">优惠券抵扣：</text>
								<text class="text-orange">该课程支持使用优惠券</text>
							</view>
							<view class="border-bottom padding-top padding-bottom" v-if="data.lesson.couponsgive==1">
								<text class="text-bold text-black">购物送券：</text>
								<text class="text-orange">购买立即赠送一张优惠券</text>
							</view>
							<view class="padding-top padding-bottom-sm" v-if="data.lesson.rebate>0">
								<text class="text-bold text-black">赠送积分：</text>
								<text class="text-orange" v-if="data.lesson.rebate==1">购买即赠送{{data.lesson.rebateamout}}积分</text>
								<text class="text-orange" v-else>购买即按购买金额1:{{data.lesson.rebateamout}}赠送积分</text>
							</view>
						</view>
					</view>
				</view>
				 <view class="tab-item padding" :class="currentshow=='comment'?'active':''">
					<view class="padding-xs flex padding-bottom border-bottom">
						<view class="score flex-sub text-xxl text-center text-bold text-black">
							<text v-if="data.lesson.score==0">--</text>
							<text v-else>{{data.lesson.score}}</text>
						</view>
						<view class="flex-quintet flex">
							<view class="flex-twice padding-left border-left-thin">
								<scorebar :score="data.lesson.score" :viewscore="false"></scorebar>
							</view>
							<button class="flex-sub cu-btn bg-gradual-yellow round sm text-white" @click="doComment(0)">我来评价</button>
						</view>
					</view>
					 <view class="padding-top-xs">
						<view class="padding-xl text-gray text-center" v-if="data.comments.length==0">评论区空空如也，快去抢沙发吧~</view>
						<view class="comments" v-else>
							<view class="cu-list menu-avatar padding-top-sm" style="margin-top: 10upx;" :class="index==0?'':'solid-top'" v-for="(item, index) in data.comments" :key="index">
								<view class="cu-item noaf">
									<view class="cu-avatar round lg" :style="'background-image:url('+item.avatar+');'"></view>
									<view class="content">
										<view>{{item.name}}</view>
										<view class="text-gray text-sm flex">
											<view class="text-cut stars text-lg">
												<text class="cuIcon-favorfill" :class="item.score>=index?'text-yellow':''" v-for="index in 5" :key="index"></text>
											</view>
										</view>
									</view>
									<view class="action">
										<view class="text-grey text-xs">{{item.datetime}}</view>
										<view class="round text-red" @click="removeComment(item.id)" v-if="userId==item.uid"><text class="cuIcon-delete"></text></view>
									</view>
								</view>
								<view class="summary">
									<text class="text-lg">{{item.content}}</text>
									<!-- 管理员回复 -->
									<!-- 管理员回复 -->
									<!-- 管理员回复 -->
									<view class="bg-gray radius padding-sm replys margin-top-xs" v-if="item.commentsByReply.length>0">
										<view class="rp-item" v-for="(value, key) in item.commentsByReply" :key="key">
											<text class="text-blue">{{value.name}}</text> 回复 <text class="text-blue">@{{item.name}}</text>：
											<text>{{value.content}}</text>
										</view>
									</view>
									<view class="grid col-4 grid-square margin-top-sm" v-if="item.pics.length>0">
										<view class="bg-img" @click="ViewCMImage(pic,item.pics)" :style="'background-image:url('+pic+');'" v-for="(pic,kee) in item.pics" :key="kee">
										</view>
									</view> 
								</view>
							</view>
							<view class="border-bottom text-center padding" @click="loadComment(commentpage+1)" v-if="data.comments.length>=15">
								<view class="text-gray">查看更多</view>
							</view>
						</view>
					</view>
					<view class="cu-modal bottom-modal" :class="showmodal=='comment'?'show':''">
						<view class="cu-dialog">
							<view class="cu-bar bg-white solid-bottom">
								<view class="action" @tap="showmodal=''">取消</view>
								<view class="action text-green" @tap="submitComment">确定</view>
							</view>
							<view class="padding-sm bg-white">
								<form>
									<view class="cu-form-group">
										<view class="title">课程评分</view>
										<view class="content">
											<view class="stars text-xxxl text-left flex">
												<text @click="selectScore(index)" class="cuIcon-favorfill flex-sub" :class="comment.score>=index?'text-yellow':'text-gray'" v-for="index in 5" :key="index"></text>
											</view>
										</view>
									</view>
									<view class="cu-form-group align-start">
										<view class="title">评价内容</view>
										<textarea class="text-left" maxlength="-1" v-model="comment.content" placeholder="简单说说学习后的感受吧~"></textarea>
									</view>
									<view class="cu-bar bg-white">
										<view class="action">
											图片上传
										</view>
										<view class="action">
											{{commentpics.length}}/4
										</view>
									</view>
									<view class="cu-form-group">
										<view class="grid col-4 grid-square flex-sub">
											<view class="bg-img" v-for="(pic,index) in commentpics" :key="index" @tap="ViewCMImage(pic,commentpics)">
											 <image :src="pic" mode="aspectFill"></image>
												<view class="cu-tag bg-red" @tap.stop="DelCMImg(index)">
													<text class='cuIcon-close'></text>
												</view>
											</view>
											<view class="solids" @tap="ChooseImage" v-if="commentpics.length<4">
												<text class='cuIcon-cameraadd'></text>
											</view>
										</view>
									</view>
								</form>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		 <view class="content margin-top-sm bg-white">
			<view class="cu-bar">
				<view class="action title-style-3">
					<text class="text-lg text-bold text-black">课程介绍</text>
				</view>
			</view>
			<view class="rich-text padding" v-if="lessoncontent!=''">
				<rich-text :nodes="lessoncontent" :selectable="true"></rich-text>
			</view>
			<view class="padding text-center" style="min-height: 100upx; line-height: 100upx;" v-else>
				<text class="text-gray padding">啊哦~忘记上传介绍了~</text>
			</view>
		</view>
		 <view class="cu-modal bottom-modal" :class="showmodal=='specs'?'show':''" v-if="!data.hasbought">
			<view class="cu-dialog">
				<view class="cu-bar bg-white">
					<view class="action text-blue" @tap="showmodal=''">取消</view>
					<view class="action text-green" @tap="createOrder(specid)">确定</view>
				</view>
				<view class="grid col-2 padding-sm">
					<view class="padding-xs">
						<button class="cu-btn orange lg block" :class="specid==0?'bg-orange':'line-orange'" @tap="specid=0"> {{data.lesson.courseprice}}元/永久</button>
					</view>
					<view class="padding-xs" v-for="(item, index) in data.specs" :key="index">
						<button class="cu-btn orange lg block" :class="specid==item.id?'bg-orange':'line-orange'" @tap="specid=item.id"> {{item.courseprice}}元/{{item.timelimit}}天</button>
					</view>
				</view>
			</view>
		</view> 
		<view class="cu-bar bg-white tabbar shop">
			<view class="action" @click="naviTo('lector/detail',{id:data.lector.id})" v-if="data.lector.uid>0">
				<view class="cuIcon-peoplelist"></view> 讲师主页
			</view>
			<view class="action" @click="doFavor('lesson',data.lesson.id)">
				<view :class="data.favor.id>0?'text-yellow':''">
					<view :class="'cuIcon-favor'+(data.favor.id>0?'fill':'')"></view> 收藏
				</view>
			</view>
			<button class="action text-muted" open-type="share" v-if="platform=='wxapp'">
				<view class="cuIcon-share"></view> 分享
			</button>
			<view class="action" @click="showshare=true" v-else>
				<view class="cuIcon-share"></view> 分享
			</view>
			<view class="btn-group">
				<button style="width: 100%;" @click="doPlay" class="cu-btn bg-gradual-green round-topleft-none lg" v-if="data.hasbought">{{data.log.id==0?'开始学习':'继续学习'}}</button>
				<button style="width: 100%;" @click="dobuy" class="cu-btn bg-gradual-yellow round-topleft-none lg" v-else>订阅课程</button>
			</view>
		</view>
		 <share :platform="platform" :shareinfo="shareinfo" @closeshare="showshare=false" :showshare="showshare"></share> 
	</view>
</template>

<script>
	import {mapState} from 'vuex'
	import core from "@/static/core.js"
	import scorebar from "@/components/util/scorebar.vue"
	import share from "@/components/util/share.vue"
	
	export default {
		components: {scorebar, share},
		computed: mapState(['userId', 'hasLogin', 'userName', 'lectorid']),
		data() {
			return {
				id:0,
				specid:0,
				currentshow:'main',
				platform:'h5',
				device:core.device,
				showmodal:'',
				showlog:true,
				lessoncontent:'',
				commentpage:1,
				showshare:false,
				shareinfo:{
					url:'',
					providers:4,
					provider:{}
				},
				commentpics:[],
				comment:{
					score:0,
					cid:0,
					content:"",
					pics:[]
				},
				data:{
					"title":"课程详情",
					"lesson": {
						"id": 0,
						"uniacid": 0,
						"uid": 0,
						"cid": 0,
						"sid": 0,
						"multiple": 0,
						"title": "",
						"coursebrief": "",
						"imgurl": "",
						"summary": "",
						"content": "",
						"tags": "",
						"views": 0,
						"collection": 0,
						"sales": 0,
						"virtuals": 0,
						"rebate": 0,
						"rebateamout": 0,
						"deduct": 0,
						"deductmax": 0,
						"discount": 0,
						"coupon": 0,
						"couponsgive": 0,
						"commission": {
							"switch": 0,
							"commission1": "",
							"commission2": "",
							"commission3": ""
						},
						"goods": {
							"switch": 0,
							"title": "",
							"cover": "",
							"summary": "",
							"url": ""
						},
						"score": 0,
						"evaluations": 0,
						"courseprice": 0.00,
						"proportion": 0,
						"difficulty": "",
						"updating": 0,
						"isrecommend": 0,
						"displayorder": 0,
						"status": 0,
						"remark": "",
						"dateline": 0,
						"addtime": 0,
						"lector": "",
						"category": "",
						"special": "",
						"studynumber": 0,
						"datetime": "",
						"createtime": "",
						"url":""
					},
					"sections": [],
					"comments":[],
					"special": {
						"id": 0
					},
					"lector":{
						"uid":0
					},
					iospay:false,
					"discounttext":"",
					"hasbought":true,
					"hascomment":false,
					"vipstate":0,
					"log": {
						"id": 0,
						"sid":0
					},
					"specs":[],
					"paylog":{
						"id":0
					},
					"favor":{
						"id":0
					}
				}
			}
		},
		onLoad(options) {
			if(typeof(options.id)=='undefined') return core.toast('参数错误：课程编号异常','home');
			this.platform = core.platform;
			this.id = options.id;
			if(this.id<=0) return core.toast('参数错误：无效的课程编号','home');
			var that = this;
			this.initData('lesson/detail',{id:this.id},function(res){
				that.lessoncontent = res.lesson.content;
				let summary = res.lesson.coursebrief=='' ? res.lesson.summary : res.lesson.coursebrief;
				that.shareinfo = core.initshare(res.lesson.title, res.lesson.url, res.lesson.cover, summary);
			});
		},
		onShow(){
			this.infoLog();
			this.initData();
		},
		onPullDownRefresh(){
			var that = this;
			this.initData('lesson/detail',{id:this.id},function(res){
				that.lessoncontent = res.lesson.content;
			});
			uni.stopPullDownRefresh();
		},
		onShareAppMessage(e){
			return {
				title:this.data.title,
				path:core.page(this.shareinfo.url)
			}
		},
		methods:{
			initData(route, data={}, callback=false){
				var that = this;
				// core.get(route,function(res){
				// 	if(typeof(res.message)!='undefined' && typeof(res.type)!='undefined'){
				// 		return core.report(res, true);
				// 	}
				// 	// that.data = res;
				// 	console.log(that.data)
				// 	uni.setNavigationBarTitle({
				// 		title:res.title
				// 	});
				// 	if(callback){
				// 		callback(res);
				// 	}
				// },data);
				this.selById();
				this.infoCourse();
				this.infoLog();
				this.infoComments();
				this.infolector();
				this.selLike();
			},
			/*查询关注讲师表*/
			async selLike(){
				var that = this;
				if(core.userinfo.uid!=0){
					var sel = (await this.$api.reqGet({
						url:"lecturer/selLike/"+core.userinfo.uid,
					})).data;
					if(sel!=null){
						for(var i = 0;i<sel.length;i++){
								if(that.data.lector.id===sel[i].lecturerId){
									that.data.lector.hasfavor = !(that.data.lector.hasfavor)
								}
						}
					}
				}
			},
			async infolector(){
				(await this.$api.reqGet({
					url:"lecturer/selByRoom/"+this.id
				}).then(res=>{
					console.log(res)
					if(res.code==200){
						this.data.lector=res.data
					}
				}))
			},
			async infoLog(){
				if(core.userinfo.uid>0){
					(await this.$api.reqGet({
						url:"menu/selLog/"+core.userinfo.uid+"/"+parseInt(this.id)
					}).then(res=>{
						console.log(res)
						if(res.code==200){
							this.data.log=res.data;
						}
					}))
				}
			},
			async infoCourse(){
				(await this.$api.reqGet({
					url:"menu/selByCourseId/"+this.id
				}).then(res=>{
					console.log(res)
					if(res.code==200){
						this.data.sections=res.data;
					}
				}))
			},
			async selById(){
				(await this.$api.reqGet({
					url:"menu/selById/"+this.id
				}).then(res=>{
					console.log(res)
					if(res.code==200){
						this.data.lesson=[];
						this.data.lesson=res.data;
						this.data.lesson.score=parseInt(res.data.score)
						this.data.lesson.goods={};
						this.data.lesson.goods.switch=0;
						console.log(this.data.lesson)
					}
				}))
			},
			naviTo(page,data={}){
				return core.navito(page,data);
			},
			ChooseImage(){
				if(this.commentpics.length>=4) return core.toast('最多上传4张图片');
				var that = this;
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						core.upload(res.tempFilePaths[0],function(res){
							that.commentpics.push(res.data);
							that.comment.pics.push(res.data);
						});
					}
				});
			},
			ViewCMImage(url,urls) {
				uni.previewImage({
					urls: urls,
					current: url
				});
			},
			DelCMImg(index){
				var that = this;
				return core.confirm('删除后不可恢复','确定要删除？',function(){
					that.commentpics.splice(index,1);
					that.comment.pics.splice(index,1);
				});
			},
			//评价
			doComment(cid=0){
				if(!this.hasLogin){
					return core.navito('auth/index',{act:'login'});
				}else{
					console.log(this.data.log)
					if(this.data.log.id>0){
						if(this.data.hascomment) return core.toast('您已经评价过了哦~');
						this.comment.cid = cid;
						this.showmodal = 'comment';
					}else{
						return core.toast('学习后再作评价吧~');
					}
				}
			},
			dobuy(){
				if(!this.hasLogin) return core.navito('auth/index',{act:'login'});
				if(this.data.specs.length==0){
					//直接进入订单页面
					return this.createOrder(0);
				}else{
					if(this.data.paylog.id>0){
						var that = this;
						return core.confirm('您有未支付的订单，是否继续支付？','购买课程',function(){
							core.navito('order/create',{tid:that.data.paylog.tid});
						},{},function(){
							that.showmodal = 'specs';
						})
					}else{
						this.showmodal = 'specs';
					}
				}
			},
			/**
			 * 开始学习 根据已学习 未学习【0】第0个视频 和没有 ：未上架
			 */
			doPlay(){
				let sid;
				if(this.data.log.sid>0){
					sid = this.data.log.sid;
				}else{
					if(this.data.sections.length>0){
						sid = this.data.sections[0].number
					}else{
						return core.toast('课程章节上传中...');
					}
				}
				return this.viewSection(sid);
			},
			/*关注讲师*/
			async doFavor(Type='lesson',id=0){
				if(Type=='lesson') return core.toast('下个版本上线');
				if(!this.hasLogin) return core.navito('auth/index',{act:'login'});
						var that = this
						that.data.lector.hasfavor = !(that.data.lector.hasfavor)
						var a = (await this.$api.reqPost({
							url:"/lecturer/ins",
							data:{
							uid:core.userinfo.uid,
							lecturerId:id,
							}
						})).data;
			},
			async infoComments(){
				var that=this;
				/**
				 * 根据被评论id和评论类型  查询评论
				 */
				(await this.$api.reqGet({
					url:"comments/selByAid/"+parseInt(this.id)+"/lesson"
				}).then(res=>{
					console.log(res)
					if(res.code==200){
						 that.data.comments=res.data;
						for(var i =0;i<that.data.comments.length;i++){
							that.data.comments[i].pics=JSON.parse(res.data[i].pics);
							if(that.data.comments[i].commentsByReply==null){
								that.data.comments[i].commentsByReply=[];
							}
						}
						console.log(that.data.comments)
						
					}else{
						that.data.comments=[]
					}
				}));
			},
			async submitComment(){
				if(!this.hasLogin) return core.navito('auth/index',{act:'login'});
				if(this.comment.score==0) return core.toast('请对课程质量进行评分');
				if(this.comment.content=='') return core.toast('请输入您的评价内容');
				var postdata = this.comment ;
				console.log(this.comment)
				postdata.type = 'lesson';
				postdata.aid = this.data.lesson.id;
				postdata.uid=core.userinfo.uid;
				postdata.pics=JSON.stringify(this.comment.pics);
				var that = this;
				console.log(postdata)
				that.infoComments();
				(await this.$api.reqPost({
					url:"comments/addComments",
					data:postdata
				}).then(res=>{
					console.log(res)
					if(res.code==200){
						that.showmodal = '';
						core.toast('评论成功','','success');
						that.data.hascomment = true;
						that.infoComments();
						this.selById();
					}else if(res.code==4002){
						core.toast(res.msg);
					}
				}))
				// return core.post('comment/post',function(res){
				// 	if(res.type!='success') return core.toast(res.message);
				// 	core.toast(res.message,'','success');
				// 	that.showmodal = '';
				// 	that.data.hascomment = true;
				// 	that.loadComment(1);
				// },{data:postdata});
			},
			selectScore(score){
				this.comment.score = score;
			},
			createOrder(specid=0){
				if(!this.hasLogin) return core.navito('auth/index',{act:'login'});
				core.post('lesson/buy',function(res){
					if(res.type!='success') return core.report(res);
					core.navito('order/create',{tid:res.message.tid});
				},{id:this.data.lesson.id,spec:specid});
			},
			viewSection(sid){
				if(!this.hasLogin) return core.navito('auth/index',{act:'login'});
				if(!this.data.hasbought) return this.dobuy();
				if(!sid) return core.toast('参数异常：无效的章节');
				// this.data.lessons.studynumber=this.data.lessons.studynumber+1;
				
				return core.navito('lesson/section',{id:this.data.lesson.id, sid:sid})
			},
			loadComment(page=1){
				var that = this;
				return core.get('comment',function(res){
					if(page==1){
						that.commentpage = 1;
						that.data.comments = res.list;
					}else{
						if(res.list.length==0) return core.toast('没有更多了~');
						that.data.comments = that.data.comments.concat(res.list)
					}
				},{type:'lesson',aid:this.data.lesson.id,cid:0,page:page});
			},
			removeComment(cid=0){
				if(!this.hasLogin) return core.navito('auth/index',{act:'login'});
				if(!cid) return core.toast('参数异常：无效的评论编号');
				var that = this;
				return core.confirm('删除后不可恢复，是否确定要删除？','删除评价',function(){
					(that.$api.reqGet({
						url:"comments/deById/"+cid
					}).then(res=>{
						console.log(res);
						if(res.code==200){
							that.infoComments();
							that.data.hascomment = false;
						}
					}))
				});
			}
		}
	}
</script>

<style>
	page{background-color: #FFFFFF;}
	.container.bar{background: #F2F2F2;}
	.cu-bar.tabbar{padding: 0 18upx;}
	.cu-bar.tabbar.shop .action{width: 120upx;}
	.bg-gray.light .title{color: #777777; padding-bottom: 0.32rem;}
	.bg-gray.light .title~text{color: #222222; font-size: 0.8rem; font-weight: 600;}
	.text-novip{position: relative; display: inline-block; width: calc(100% - 180upx);}
	.text-novip::after{content: '去升级'; position: absolute; height: 100%; right: 0; top: 0; font-size: 24upx; color: #f37b1d; line-height: 42upx;}
</style>
